# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper

  def editor?
    current_user && current_user.editor?
  end

  def admin?
    current_user && current_user.admin?
  end

  def error_messages_on(object, method, prepend_text = "", append_text = "", css_class = "formError")
    if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) && (errors = obj.errors.on(method))
      errors_list = errors.map {|error| "#{prepend_text}#{error}#{append_text}<br />"}.join
      content_tag("div", errors_list, :class => css_class)
    else 
      ''
    end
  end


  def each_days(begin_at, end_at)
    date = begin_at
    while date <= end_at
      yield date
      date = date.tomorrow
    end
  end

  def each_month(begin_at, end_at)
    date = begin_at
    while date <= end_at
      yield date
      date = date.next_month.beginning_of_month
    end
  end

end
